app.get('/devices', function(req, res) {
	model.Device.find(function(e, devices) {
		if (e) {

		} else {
			res.render('devices.jade', {
				pageTitle : 'Devices',
				devices : devices,
				pretty : true
			});
		}
	});
});

app.get('/devices/:id', function(req, res, next) {
	model.Device.findOne({
		_id : req.params.device
	}, function(e, device) {
		model.Message.error(e);
		if (device) {
			model.Port.find({
				device : device._id
			}, function(e, ports) {
				model.Message.error(e);
				res.render('editDevice.jade', {
					pageTitle : 'Device Configuration',
					device : device,
					ports : ports,
					pretty : true
				});
			});
		} else {
			model.Message.warn('Unable to find device ' + req.params.device);
			res.render('message.jade', {
				pageTitle : 'Message',
				type : 'Warning',
				date : Date.now(),
				message : 'Unable to find device ' + req.params.device
			});
		}
	});
});
